package com.zxy.controller;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.zxy.dao.IDNumberTopSixDao;
import com.zxy.utils.ServletUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.zxy.utils.JSONUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;

@WebServlet("/idTopSix")
public class IdTopSix extends HttpServlet {

    private static Logger logger = LogManager.getLogger(IdTopSix.class);
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("application/json;charset=utf-8");
        PrintWriter out = response.getWriter();
        Gson gson = new Gson();
        String json = JSONUtil.getJSONData(request);
        JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject();
        
        String idTopSix =jsonObject.get("IDTopSix").getAsString();
        
        HashMap<String, String> map = new HashMap<>();
        map.put("id",idTopSix);
        String s = IDNumberTopSixDao.checkAddress(map);
        logger.info(s);
        HashMap<String, String> resultMap = new HashMap<>();
        resultMap.put("address", s);
        out.write(gson.toJson(resultMap));
    }
    
    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
    
    
}
